
if exists(select name from sysobjects where name = 'sp_NewsCreateEdit')
	drop proc sp_NewsCreateEdit
go
/*
	Created by: Phuoc NH
	Created on: 13/05/2013 (dd/mm/yyyy)
	Description: 
	--

	File:$sql-scripts/Proc.sp_NewsCreateEdit.sql
*/


-- =============================================
-- Author		: HP
-- Create date	: 2014-03-23
-- =============================================

CREATE PROCEDURE sp_NewsCreateEdit
			
	@Id         		INT,
	@Name       		NVARCHAR(256)=null,
	@Tag        		NVARCHAR(256)=null,
	@Image      		VARCHAR(256)=null,
	@Content    		NVARCHAR(512)=null,
	@Detail     		NTEXT=null,
	@Date       		VARCHAR(15)=null,
	@Title      		NVARCHAR(256)=null,
	@Description		NVARCHAR(256)=null,
	@Keyword    		NVARCHAR(512)=null,
	@Priority   		INT,
	@Index      		INT,
	@Active     		INT,
	@GroupNewsId		INT,
	@Lang       		VARCHAR(5)=null
	
AS
BEGIN
    IF(@Id=0)
        BEGIN
        	INSERT INTO News
        	(
		[Name],
		[Tag],
		[Image],
		[Content],
		[Detail],
		[Date],
		[Title],
		[Description],
		[Keyword],
		[Priority],
		[Index],
		[Active],
		[GroupNewsId],
		[Lang]
        	) 
        	VALUES 
        	(
		@Name,
		@Tag,
		@Image,
		@Content,
		@Detail,
		@Date,
		@Title,
		@Description,
		@Keyword,
		@Priority,
		@Index,
		@Active,
		@GroupNewsId,
		@Lang
        	)
        END
     ELSE
        BEGIN
            UPDATE News     
            SET
		[Name]        = @Name,
		[Tag]         = @Tag,
		[Image]       = @Image,
		[Content]     = @Content,
		[Detail]      = @Detail,
		[Date]        = @Date,
		[Title]       = @Title,
		[Description] = @Description,
		[Keyword]     = @Keyword,
		[Priority]    = @Priority,
		[Index]       = @Index,
		[Active]      = @Active,
		[GroupNewsId] = @GroupNewsId,
		[Lang]        = @Lang
	WHERE
		    [Id]       = @Id;
        END
END
GO


